package com.oauth.entity;

/**
 * @Date 2022/1/29 17:42
 * @Author com.lwj
 */
public class RestEntity<T> {

	protected String channel;

	protected T entity;

	protected boolean success = true;

	protected Integer code;

	protected String errMsg;


	public static RestEntity error(String errmsg){
		return error(errmsg,500);
	}
	public static RestEntity error(String errmsg,Integer errcode){
		RestEntity entity=new RestEntity();
		entity.setErrMsg(errmsg);
		entity.setCode(errcode);
		entity.setSuccess(false);
		return entity;
	}
	public static<T> RestEntity<T> success(T t){
		RestEntity entity=new RestEntity();
		entity.setEntity(t);
		entity.setCode(200);
		entity.setSuccess(true);
		return entity;
	}
	public static RestEntity success(){
		RestEntity entity=new RestEntity();
		entity.setCode(200);
		entity.setSuccess(true);
		entity.setEntity("操作成功");
		return entity;
	}
	public static RestEntity error(){
		RestEntity entity=new RestEntity();
		entity.setCode(500);
		entity.setSuccess(false);
		entity.setEntity("系统异常");
		return entity;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}
}
